In [ ]:

Demo of imports


In [1]:
import pdict

In [2]:
pdict.manip


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-dae786ae0307> in <module>()
----> 1 pdict.manip

AttributeError: 'module' object has no attribute 'manip'

In [3]:
import pdict.manip

In [4]:
pdict.manip


Out[4]:
<module 'pdict.manip' from '/D/Dropbox/dev/py/proj/ms_utils/pdict/manip.py'>

In [5]:
pdict.manip.add_defaults({2:3,10:10000}, {1:2, 2:2222})


Out[5]:
{1: 2, 2: 3, 10: 10000}

In [6]:
add_defaults({2:3,10:10000}, {1:2, 2:2222})


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-6-83167fb9941e> in <module>()
----> 1 add_defaults({2:3,10:10000}, {1:2, 2:2222})

NameError: name 'add_defaults' is not defined

In [7]:
from pdict.manip import add_defaults

In [8]:
add_defaults({2:3,10:10000}, {1:2, 2:2222})


Out[8]:
{1: 2, 2: 3, 10: 10000}

In [11]:
from pdict.manip import *

In [12]:
import pdict.manip as pooo

In [ ]:


In [ ]:

What is star and double star?


In [11]:
w = [1,2,3]
w


Out[11]:
[1, 2, 3]

In [15]:
def f(*args):
    print args[0]

In [18]:
f(1,2,3)


1

In [17]:
f(*w)


1

In [19]:
*w


  File "<ipython-input-19-58afbb97a22c>", line 1
    *w
    ^
SyntaxError: invalid syntax

In [20]:
d = {1:2, 10:20, 'sdf':'sans domicile fixe'}

In [21]:
d.keys()


Out[21]:
[1, 10, 'sdf']

In [22]:
d.values()


Out[22]:
[2, 20, 'sans domicile fixe']

In [25]:
t = zip(d.keys(),d.values())
t


Out[25]:
[(1, 2), (10, 20), ('sdf', 'sans domicile fixe')]

In [28]:
{k:v for k,v in zip(d.keys(), d.values())}


Out[28]:
{1: 2, 10: 20, 'sdf': 'sans domicile fixe'}

In [30]:
**d


  File "<ipython-input-30-5b50c794ce99>", line 1
    **d
     ^
SyntaxError: invalid syntax

In [33]:
def ff(a,b,c):
    print a
    print b
    print c

In [34]:
ff((1,2),(3,4),('asd','asddddd'))


(1, 2)
(3, 4)
('asd', 'asddddd')

In [39]:
dict({1:111, 10:1000}, **d)


Out[39]:
{1: 2, 10: 20, 'sdf': 'sans domicile fixe'}

In [38]:
d


Out[38]:
{1: 2, 10: 20, 'sdf': 'sans domicile fixe'}

In [40]:
dict({1:111, 10:1000}, {4:44}, {5:55})


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-40-fc9055dc68db> in <module>()
----> 1 dict({1:111, 10:1000}, {4:44}, {5:55})

TypeError: dict expected at most 1 arguments, got 3

Misc


In [41]:
2**4


Out[41]:
16

In [42]:
2^4


Out[42]:
6

In [43]:
2^10


Out[43]:
8

In [62]:
[x^10 for x in range(20)]


Out[62]:
[10, 11, 8, 9, 14, 15, 12, 13, 2, 3, 0, 1, 6, 7, 4, 5, 26, 27, 24, 25]

In [63]:
[x^1 for x in range(20)]


Out[63]:
[1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18]

In [64]:
[x^0 for x in range(20)]


Out[64]:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]

In [65]:
[x^2 for x in range(20)]


Out[65]:
[2, 3, 0, 1, 6, 7, 4, 5, 10, 11, 8, 9, 14, 15, 12, 13, 18, 19, 16, 17]

In [66]:
[x^3 for x in range(20)]


Out[66]:
[3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8, 15, 14, 13, 12, 19, 18, 17, 16]

In [44]:
2.^10


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-44-71dc8b90bcf9> in <module>()
----> 1 2.^10

TypeError: unsupported operand type(s) for ^: 'float' and 'int'

In [45]:
2^10.


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-45-01daf3a78df0> in <module>()
----> 1 2^10.

TypeError: unsupported operand type(s) for ^: 'int' and 'float'

In [ ]: